define([
        'Util',
        'text!tpl/order/addOrder.tpl',
        'select',
        'provincesSelect',
        'date',
        'list',
        'form',
        'upload',
        'dialog',
        'jquery',
        'checkboxes',
        'validator',
        'loading',
        'cookie',
        '../common/getPath',
        'comboSelect',
        'radios'
    ],
    function (Util, tpl, Select, provincesSelect,  MyDate,List ,Form, Upload, Dialog, $, Checkboxes, Validator, Loading, $cookie, AjaxPath, ComboSelect, Radios) {
        require(['style!css/style.css']);
        //系统变量-定义该模块的根节点
        var $el = null;
        var _indexModule = null,
            tabOrder = null,
            departmentSelect = null,
            departmentSelectValue = null,
            rankFrom = null,
            rankFromSelectValue = null,
            proposeDate = null,
            tryOrder = null,
            ContractProgress = null,
            zzfhDateDate = null,
            zwfhDateDate = null,
            deviceType = null,
            OrderValidation = null,
            OrderValidationOne = null,
            delFlag = false,
            reqAttachmentIdList = [],
            orderPersonName = null,
            organName = null,
            phone = null,
            email = null,
            filesUpload = null,
            uploadConfig = null,
            getUserId = null,
            uploadDialog = null,
            submitOrder = "submitOrder",
            saveOrder = "saveOrder",
            OrderValidationTwo = null,
            tagListSelectList = [],
            encodeThree=null,
            fileStatus = false;


        //系统变量-构造函数
        var initialize = function(indexModule, options, tabItem) {
            reqAttachmentIdList = [];
            tagListSelectList = [];
            $el = $(tpl);
            _indexModule = indexModule;
            $(tabItem).on("tabActive", function() {
                tabItem.show(true); //刷新表单
            });
            addOrderData = options;
            tabOrder = tabItem;
            this.content = $el;
            eventInit();
            Irrevocable();
            addWorkOrder();
            fileUp();
            addOrderValidation();
            /*var encodeOne= encodeURI(encodeURI("./assets/files/ShouHuoDiZhiTianXieMuBan.xlsx"));
            $('.templateOne',$el).attr('href',encodeOne);
            encodeThree= encodeURI(encodeURI("./assets/files/CaiGouDingDanMuBan.docx"));
            $('.templateThree',$el).attr('href',encodeThree);*/
            
        };
        /*保存 或提交*/
        var addOrderBtn=function (addOrder) {
            if(!fileStatus){
                new Dialog({
                    mode: 'tips',
                    delayRmove:1.5, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                    tipsType:'success', //tips类型；可选 success | error，默认普通tips。
                    width:320,
                    height:180,
                    content: '<div style="text-align:center;margin-top:90px">附件上传中</div>'
                });
                return false;
            }
            var attachmentsIds="";
            for(var i=0;i<reqAttachmentIdList.length;i++){
                attachmentsIds+=reqAttachmentIdList[i]+",";

            }
            objOrder={
                "orderPersonId": getUserId,
                "orderPersonName": $('.userName',$el).val(),
                "organName": $('.organName',$el).val(),
                "phone":$('.phone',$el).val(),
                "email":$('.email',$el).val(),
                "orderName":$('.orderName',$el).val(),          //工单标题
                "demandEmployer":departmentSelectValue.dictValue,      //需求单位
                "priority":rankFromSelectValue.dictValue,                //优先级
                "orderTime":$('.orderTime',$el).val(),              //提出时间
                "deliveryFirstTime":$('.deliveryFirstTime',$el).val(),  //最早发货时间
                "deliveryLastTime":$('.deliveryLastTime',$el).val(),    //最晚发货时间
                "equipmentType":deviceType.getSelected().id,              //设备类型
                "equipmentNum":Number($('.deviceNumber',$el).val()),            //设备数量
                "addrProvince":$("#province ", $el).val(),                                     //省
                "addrCity":$("#city ", $el).val(),                                          //市区
                "addrCounty":$("#town ", $el).val(),                                        //县城
                "address":$('.detailedAddress',$el).val(),             //详细地址
                "contact":$('.mainContacts',$el).val(),                 //联系人
                "contactPhone":$('.contactPhone',$el).val(),            // 联系电话
                "attachmentsIds":attachmentsIds,                                   //附件id
                "assignPerson":$cookie.get("userId")                                 //当前登录人


            };
            departmentSelectValue= departmentSelect.getSelected();
            if(departmentSelectValue.dictName==="客户采购"){
                objOrder.taxPrice=($('.taxPrice',$el).val());
                objOrder.noTaxPrice=$('.noTaxPrice',$el).val();
                objOrder.taxTotal=($('.taxTotal',$el).val())*($('.deviceNumber',$el).val());
                objOrder.noTaxTotal=($('.noTaxTotal',$el).val())*($('.deviceNumber',$el).val());
                //objOrder.orderType=tryOrder.getSelected().dictValue;
                objOrder.contractStatus=ContractProgress.getSelected().dictValue;
                objOrder.noTaxPrice=$('.noTaxPrice',$el).val();
                objOrder.noTaxTotal=$('.noTaxTotal',$el).val();
                objOrder.taxPrice=$('.taxPrice',$el).val();
                objOrder.taxTotal=$('.taxTotal',$el).val();
                objOrder.contractName=$('.contractName',$el).val();
                objOrder.contractCode=$('.contractCode',$el).val();

            }else{
                //objOrder.orderType="";
                objOrder.contractStatus="";
                objOrder.contractName="";
                objOrder.contractCode="";
                objOrder.noTaxPrice=Number(deviceType.getSelected().equipmentNotaxPrice);
                objOrder.noTaxTotal=Number(deviceType.getSelected().equipmentNotaxPrice)*($('.deviceNumber',$el).val());
                objOrder.taxPrice=Number(deviceType.getSelected().equipmentPrice);
                objOrder.taxTotal=Number(deviceType.getSelected().equipmentPrice)*($('.deviceNumber',$el).val());

            }
            //console.log(objOrder);
          /*  if($('.htbm,.htmc',$el).is(":hidden")){
                $('.contractCode',$el).removeAttr("contractCode");
                $('.contractName',$el).removeAttr("contractName");
                alert(111)
            }else{
                $('.contractCode',$el).attr("contractCode","contractCode");
                $('.contractName',$el).attr("contractName","contractName");
                alert(222)
            }*/
            var getAddOrder=function () {
                Util.ajax.postJson(AjaxPath.management+"/order/"+addOrder, JSON.stringify(objOrder), function(result, isok) {
                    if (result.returnCode === "0000") {
                        // if(objOrder="saveOrder"){
                        /*new Dialog({
                         mode: 'tips',
                         delayRmove:1.5, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                         tipsType:'success', //tips类型；可选 success | error，默认普通tips。
                         width:320,
                         height:180,
                         content: '<div style="text-align:center;margin-top:90px">' + result.returnMessage + '</div>'
                         });*/
                        // }else{
                        new Dialog({
                            mode: 'tips',
                            delayRmove:1.5, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                            tipsType:'success', //tips类型；可选 success | error，默认普通tips。
                            width:320,
                            height:180,
                            content: '<div style="text-align:center;margin-top:90px">' + result.returnMessage + '</div>'
                        });
                        setTimeout(function () {
                            back();
                        },1500);
                        // }
                    } else {
                        new Dialog({
                            mode: 'tips',
                            delayRmove:2, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                            tipsType:'success', //tips类型；可选 success | error，默认普通tips。
                            width:320,
                            height:180,
                            content: '<div style="text-align:center;margin-top:90px">' + result.returnMessage + '</div>'
                        });
                    }



                },"application/json")
            };
            departmentSelectValue= departmentSelect.getSelected();

            if(departmentSelectValue.dictName==="客户采购"){
                if($('.htbm,.htmc',$el).is(":hidden")){
                    if(OrderValidation.form()&&OrderValidationOne.form()){
                        getAddOrder();
                    }else{
                        console.log("验证失败")
                    }
                 }else{
                    if(OrderValidation.form()&&OrderValidationOne.form()&&OrderValidationTwo.form()){
                        getAddOrder();
                    }else{
                        console.log("验证失败")
                    }
                 }


            }else{
                if(OrderValidation.form()) {
                    getAddOrder();
                }else{
                    console.log("验证失败")
                }
            }
        };


        //业务代码-事件初始化
        var eventInit = function() {
            $el.on('click', '.submitBtn', function () {
                addOrderBtn(submitOrder);
            });
            $el.on('click', '.saveBtn', function () {
                addOrderBtn(saveOrder);
            });
          /*  $el.on('click', '.templateOne', templateOne);
            $el.on('click', '.templateThree', templateThree);
            $el.on('click', '.templateTwo', templateTwo);*/
            $el.on('click', '.btnBack', back);
        };
        /*var templateThree=function () {//合同关键页
            var decodeThree= decodeURI(encodeThree);
        	$('.templateThree',$el).attr('href',decodeThree);
        };*/
       
      /*  /!*模板下载*!/
        var templateOne=function () {
            window.location.href="http://192.168.26.27:8001/file-service/dev-yanfayun/bbe4357a-afc9-4227-a255-415d8ccd8754/%E6%94%B6%E8%B4%A7%E5%9C%B0%E5%9D%80%E5%A1%AB%E5%86%99%E6%A8%A1%E6%9D%BF.xlsx"; //地址模板
        };
        var templateThree=function () { //采购模板
            window.location.href="http://192.168.26.27:8001/file-service/dev-yanfayun/91f5c4d3-97d5-4bdb-8c21-73745d3b142d/%E9%87%87%E8%B4%AD%E8%AE%A2%E5%8D%95%E6%A8%A1%E6%9D%BF.docx"
        };
        var templateTwo=function () {//合同关键页
            window.location.href="http://192.168.26.27:8001/file-service/dev-yanfayun/5df4f8ec-59bd-48ff-8909-f064b72088a8/%E5%90%88%E5%90%8C%E5%85%B3%E9%94%AE%E9%A1%B5.pdf";
        };*/


        var back = function() {
            tabOrder.switchTab(addOrderData.menuId);
            tabOrder.destroy("addOrderTab");
        };

        /*禁用不可更改该$cookie.get("userId")*/
        var Irrevocable=function () {
            $('.templateOne',$el).show();
            $('.templateFour',$el).show();
            //$('.htbm',$el).hide();
            Util.ajax.getJson(AjaxPath.management+"/SysUser/"+$cookie.get("userId"), function(result, isok) {
                getUserId=result.bean.userId;
                //console.log(result.bean.userId)
                result.bean.userName===null?result.bean.userName="":result.bean.userName;
                result.bean.userDuty===null?result.bean.userDuty="":result.bean.userDuty;
                result.bean.phone===null?result.bean.phone="":result.bean.phone;
                result.bean.email===null?result.bean.email="":result.bean.email;
                orderPersonName='<input class="userName" type="text"value="'+result.bean.userName+'" name="userName"disabled="disabled" maxlength="50"/>';
                organName='<input class="organName" type="text"value="'+result.bean.userDuty+'" name="userDuty"disabled="disabled" maxlength="50"/>';
                phone='<input class="phone" type="text"value="'+result.bean.phone+'" name="phone"disabled="disabled" maxlength="50"/>';
                email='<input class="email" type="text"value="'+result.bean.email+'" name="email"disabled="disabled" maxlength="50"/>';
                $('.getPerson',$el).html(orderPersonName);
                $('.getDepartment',$el).html(organName);
                $('.getCellPhoneNumber',$el).html(phone);
                $('.getEmailAddress',$el).html(email);
            });
        };
        /*需求单位*/
        var addWorkOrder=function () {
            Util.ajax.getJson(AjaxPath.management+"/dict/dropDown?businessModual=orderList&businessType=demandEmployer", function(result, isok) {
                //console.log(result.beans);
                var departmentConfig = {
                    el:$(".demandEmployer", $el),       //要绑定的容器
                    name:'demandEmployer',    //下拉框单元添加name属性
                    checked:'0',
                    textField:"dictName",   //设置下拉框内容，填写数据中对应的字段名
                    valueField:"id",//设置下拉框value，填写数据中对应的字段名//默认选中
                    datas: result.beans         //数据源与url模式可二选一
                };
                departmentSelect= new ComboSelect(departmentConfig);
                departmentSelectValue= departmentSelect.getSelected();
                $('.combo-input, .text-input',$el).attr("readonly","readonly");
                departmentSelect.change(function(e,valueObj){
                    //console.log(e)
                    departmentSelectValue= departmentSelect.getSelected();
                    if(e.target.selectedIndex===0){

                        $('.khcg,.htbm,.htmc,.xdlx,.htqk',$el).hide();
                        $('.templateTwo',$el).hide();
                        

                    }else{

                        departmentSelectValue= departmentSelect.getSelected();
                        //console.log( departmentSelectValue);
                        $('.khcg,.xdlx,.htqk',$el).show();
                    }

                    if(departmentSelectValue.dictName==="客户采购"){
                        var taxTotal="";
                        var noTaxTotal="";
                        var noTaxPrice="";
                        var taxPrice="";
                        $el.on('blur', '.deviceNumber,.noTaxPrice,.taxPrice', function () {
                            taxTotal=($('.deviceNumber',$el).val()) * ($('.taxPrice',$el).val());
                            noTaxTotal= ($('.deviceNumber',$el).val()) * ($('.noTaxPrice',$el).val());

                            $('.taxTotal',$el).val(Number(taxTotal).toFixed(2));
                            $('.noTaxTotal',$el).val(Number(noTaxTotal).toFixed(2));

                        });
                        $el.on('blur', '.noTaxPrice', function () {
                            noTaxPrice= $('.noTaxPrice',$el).val();
                            $('.noTaxPrice',$el).val(Number(noTaxPrice).toFixed(2));
                        });
                        $el.on('blur', '.taxPrice', function () {
                            taxPrice= $('.taxPrice',$el).val();
                            $('.taxPrice',$el).val(Number(taxPrice).toFixed(2));

                        });

                        $('.templateOne',$el).show();
                        $('.templateThree',$el).show();
                        $('.templateFour',$el).hide();
                        $('.ali',$el).hide();
                        if(ContractProgress.getSelected().dictName==="已签署"){
                            $('.templateTwo',$el).show();
                            $('.htbm,.htmc',$el).show();
                        }
                        ContractProgress.on("change",function(e,valueObj){
                            if(valueObj.dictValue===0){
                                $('.templateTwo',$el).show();
                                $('.templateFive',$el).hide();
                                $('.htbm,.htmc',$el).show();
                                departmentSelect.change(function(e){
                                    if(e.target.selectedIndex===0){
                                        $('.htbm,.htmc',$el).hide();
                                        $('.templateTwo',$el).hide();
                                    }else{
                                        $('.htbm,.htmc',$el).show();
                                        $('.templateTwo',$el).show();
                                        $('.templateFive',$el).hide();
                                    }
                                });
                            }else{
                                $('.templateTwo',$el).hide();
                                $('.templateFive',$el).show();
                                $('.htbm,.htmc',$el).hide();
                                departmentSelect.change(function(e){
                                    $('.htbm,.htmc',$el).hide();
                                    if(e.target.selectedIndex===0){
                                        $('.templateFive',$el).hide();
                                        $('.templateTwo',$el).hide();
                                    }else{
                                        $('.templateFive',$el).show();
                                        $('.templateTwo',$el).hide();
                                    }

                                });
                            }


                        });
                    }else {
                        $('.templateOne',$el).show();
                        $('.templateFour',$el).show();
                        $('.templateThree',$el).hide();
                        $('.htbm,.htmc',$el).hide();
                        $('.ali',$el).show();

                    }

                });


            });

            /*优先级*/

            Util.ajax.getJson(AjaxPath.management+"/dict/dropDown?businessModual=orderList&businessType=priority", function(result, isok) {
                //console.log(result.beans);
                var rankConfig = {
                    el:$(".rankTo", $el),       //要绑定的容器
                    name:'rankTo',    //下拉框单元添加name属性
                    checked:'1',
                    textField:"dictName",   //设置下拉框内容，填写数据中对应的字段名
                    valueField:"id",//设置下拉框value，填写数据中对应的字段名//默认选中
                    datas: result.beans         //数据源与url模式可二选一
                };
                rankFrom= new ComboSelect(rankConfig);
                rankFromSelectValue= rankFrom.getSelected();
                $('.combo-input, .text-input',$el).attr("readonly","readonly");
                rankFrom.change(function(e){
                    if(e.target.selectedIndex===0){
                        //console.log( rankFromSelectValue)
                    }
                });

            });
            //提出日期
            proposeDate = new MyDate({
                el: $("#proposeDate", $el),
                inputClassName: 'orderTime',
                label: '<i style="color:red;padding:2px;">*&nbsp;</i>提出日期:',
                name: 'starTime',    //开始日期文本框name
                isReadOnly: true,  //项可设置日期输入框是否只读
                range: false,
                type: "date",
                isDisabled: false,//是否禁用组件
                defaultValue:nowTime(0,'yyyy-MM-dd'),
                btns: ['now', 'confirm'],
                done: function(dates,value,planStartDate){
                    zzfhDateDate.options.min = dates;

                }
            });

            /*下单类型和合同情况以及含不含税单价*/
            customerPurchase();
            //最早发货日期
            zzfhDateDate = new MyDate({
                el: $("#zzfhDate", $el),
                inputClassName: 'deliveryFirstTime',
                label: '<i style="color:red;padding:2px;">*&nbsp;</i>最早发货日期:',
                name: 'startTime',    //开始日期文本框name
                isReadOnly: true,  //项可设置日期输入框是否只读
                range: false,
                type: "date",
                isDisabled: false,//是否禁用组件
                defaultValue:""/*nowTime(0,'yyyy-MM-dd')*/,
                btns: ['now', 'confirm'],
                done: function(dates,value,planStartDate){
                    zwfhDateDate.options.min = dates; //最晚发货日期最小日期
                    proposeDate.options.max = dates; //最晚发货日期最小日期
                }

            });
            zzfhDateDate.options.min=nowTime(0,'yyyy-MM-dd');
            //最晚发货日期
            zwfhDateDate = new MyDate({
                el: $("#zwfhDate", $el),
                inputClassName: 'deliveryLastTime',
                label: '<i style="color:red;padding:2px;">*&nbsp;</i>最晚发货日期:',
                name: 'endTime',    //开始日期文本框name
                isReadOnly: true,  //项可设置日期输入框是否只读
                range: false,
                type: "date",
                isDisabled: false,//是否禁用组件
                defaultValue:""/*nowTime(0,'yyyy-MM-dd')*/,
                btns: ['now', 'confirm'],
                done: function(dates,value,planStartDate){
                    zzfhDateDate.options.max = dates; //最早发货日期最大
                    //console.log(dates)
                }
            });
            zwfhDateDate.options.min=nowTime(0,'yyyy-MM-dd');
            //设备类型
            Util.ajax.getJson(AjaxPath.management+"/order/equipmentType", function(result, isok) {
                //console.log( result.beans  )
                var deviceTypeConfig = {
                    el:$("#deviceType", $el),       //要绑定的容器
                    ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置，<span class="s">慎用</span>
                        method:'GET'
                    },
                    label:'<i style="color:red;padding:2px;">*&nbsp;</i>设备类型:', //下拉框单元左侧label文本，可不配置
                    selectText:false,       //是否显示  ‘选择|清除’  模式
                    name:'equipmentName',    //下拉框单元右侧下拉框名称
                    disabled:false,     //组件是否被禁用
                    topOption:"请选择", //设置最顶部option的text属性
                    value:'',//初始选中项设置 默认是按value，如果你想按id设置 也可以 value:[&quot;id&quot;,1],这样设置
                    textField:"equipmentName",   //设置下拉框内容，填写数据中对应的字段名
                    valueField:"equipmentPrice",//设置下拉框value，填写数据中对应的字段名
                    datas: result.beans,         //数据源
                    loadAtClick:false,// true--第一次点击时渲染|false或不配置--初始化时渲染
                    dataReady:function(){

                    }
                };
                deviceType= new Select(deviceTypeConfig);
                deviceType.setValue(0);
            });


        };

        /*需求单位为客户采购的时候显示下单类型和合同情况以及含不含税单价 总部下单，分公司下单*/
        var customerPurchase=function () {
            //合同情况
            Util.ajax.getJson(AjaxPath.management+"/dict/dropDown?businessModual=orderList&businessType=contractStatus", function(result, isok) {
                var ContractProgressConfig = {
                    el:$("#contract", $el),       //要绑定的容器
                    ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置，<span class="s">慎用</span>
                        method:'GET'
                    },
                    label:'<i style="color:red;padding:2px;">*&nbsp;</i>合同情况:', //下拉框单元左侧label文本，可不配置
                    selectText:false,       //是否显示  ‘选择|清除’  模式
                    name:'contract',    //下拉框单元右侧下拉框名称
                    disabled:false,     //组件是否被禁用
                    topOption:"", //设置最顶部option的text属性
                    value:'dictValue',//初始选中项设置 默认是按value，如果你想按id设置 也可以 value:[&quot;id&quot;,1],这样设置
                    textField:"dictName",   //设置下拉框内容，填写数据中对应的字段名
                    valueField:"dictValue",//设置下拉框value，填写数据中对应的字段名
                    datas:result.beans,         //数据源
                    loadAtClick:false,// true--第一次点击时渲染|false或不配置--初始化时渲染
                    dataReady:function(){
                        //console.log("合同情况");
                    }
                };
                ContractProgress= new Select(ContractProgressConfig);
                ContractProgress.setValue(0);
            });


            /*主要收货地址*/
            var AddressSelect=new provincesSelect({
                    elProvices:$("#province", $el),
                    elCity:$("#city", $el),
                    elTown:$("#town", $el)
                }
            );
            //console.log(AddressSelect);
            //console.log($("#province ", $el).val())
        };

        /*表单验证*/
        var addOrderValidation = function() {
            OrderValidation = new Validator({
                el: $(".addOrderForm", $el),
                submitBtn: $(".submitBtn,.saveBtn",$el), //触发验证的按钮，可不配置
                dialog: true, //是否弹出验证结果对话框
                pattern: { intege1:"^[1-9]\\d*$",tel:"^[0-9\\-()（）]{7,18}$"},
                rules: {
                    orderName: "required",
                    startTime: "required",
                    endTime: "required",
                    deviceNumber: "required|intege11",
                    province: "required",
                    city: "required",
                    town: "required",
                    detailedAddress: "required",
                    demandEmployer: "required",
                    contact: "required",
                    contactPhone: "required|tel",
                    equipmentName: "required"
                },
                messages: {
                    orderName: {
                        required: "工单标题不能为空！"
                    },
                    startTime: {
                        required: "最早发货时间不能为空"
                    },
                    endTime: {
                        required: "最晚发货时间不能为空"
                    },
                    deviceNumber: {
                        required: "设备数量不能为空",
                        intege11: "请输入正整数"
                    },
                    province: {
                        required: "请选择所在省份"
                    },
                    city: {
                        required: "请选择所在市区"
                    },
                    town: {
                        required: "请选择所在县城"
                    },
                    detailedAddress: {
                        required: "请输入详细收货地址"
                    },
                    demandEmployer: {
                        required: "需求单位不能为空"
                    },
                    contact: {
                        required: "请输入联系人"
                    },
                    contactPhone: {
                        required: "请输入联系电话",
                        tel:"请输入正确的联系电话"
                    },
                    equipmentName: {
                        required: "请选择设备类型"

                    }
                }
            });
            OrderValidation.addMethod("intege11", function(str) {
                return new RegExp("^[1-9]\\d*$").test(str);

            });
            OrderValidationOne = new Validator({
                el: $(".addOrderForm", $el),
                submitBtn: $(".submitBtn,.saveBtn",$el), //触发验证的按钮，可不配置
                dialog: true, //是否弹出验证结果对话框
                //pattern: { intege1:"^[1-9]\\d*|0$"},
                rules: {
                    noTaxPrice: "required|taxPrice",
                    noTaxTotal: "required|taxPrice",
                    TaxPrice: "required|taxPrice",
                    taxTotal: "required|taxPrice",
                    // orderType: "required",
                    contract: "required"

                },
                messages: {
                    noTaxPrice: {
                        required: "不含税单价不能为空！",
                        taxPrice: "请输入最多两位小数点的正数"
                    },
                    noTaxTotal: {
                        required: "不含税总价不能为空",
                        taxPrice: "请输入最多两位小数点的正数"
                    },
                    TaxPrice: {
                        required: "含税单价不能为空",
                        taxPrice: "请输入最多两位小数点的正数"
                    },
                    taxTotal: {
                        required: "含税总价不能为空",
                        taxPrice: "请输入最多两位小数点的正数"
                    },
                    /*orderType: {
                     required: "下单类型不能为空"
                     },*/
                    contract: {
                        required: "合同类型不能为空"
                    }
                }
            });
            OrderValidationOne.addMethod("taxPrice", function(str) {
                return new RegExp("^(([0-9]+[\.]?[0-9]{1,2})|[1-9])$").test(str) ;

            });

            OrderValidationTwo = new Validator({
                el: $(".addOrderForm", $el),
                submitBtn: $(".submitBtn,.saveBtn",$el), //触发验证的按钮，可不配置
                dialog: true, //是否弹出验证结果对话框
                pattern: { intege1:"^[0-9a-zA-Z]+$"},
                rules: {
                    contractCode: "required",
                    contractName: "required"
                },
                messages: {
                    contractCode: {
                        required: "请输入合同编号"
                        //htbh: "请输入正确的合同编号"
                    },
                    contractName: {
                        required: "请输入合同名称"
                    }
                }
            });
            /*OrderValidationTwo.addMethod("htbh", function(str) {
             return new RegExp("^[0-9a-zA-Z]+$").test(str) ;

             });*/
        };


        //附件
        var fileUp = function () {
            fileStatus = true;
            require(['js/common/dateFormat']);
            uploadConfig = {
                el: $("#upload", $el), //组件绑定的容器
                className: 'upload', //组件外围的className
                url: AjaxPath.management+'/attachment/addFile', //组件上传的后台接口
                // url: fileAjaxPath, //组件上传的后台接口
                // deleteUrl: 'data/upload.json?name=[name]', //组件上传的后台接口
                paramName:'file'
            };
            filesUpload = new Upload(uploadConfig);


            filesUpload.on('submit',function(e,data){
                //formData的数据会和二进制数据一起提交到服务端
                fileStatus = false;
                data.formData = { creator:$cookie.get("userId"), businessType:'require', type:1 };
                // data.formData = { creator:1, businessType:'require', type:1 };

            });
            filesUpload.on('done',function(e,data){
                if(data.files[0].size === 0){
                	var name=data.files[0].name;
					var ael=$('#upload tbody.files').find('[title]')
					$.each(ael, function(i, obj) {
						// console.log(obj,obj.text);
						if(obj.text==name){
							$(obj).parent().parent().parent().remove();
						}
					})
                    //$('#upload .files>tr:last-child',$el).remove();
                    new Dialog({
                        mode: 'tips',
                        delayRmove:2, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                        tipsType:'success', //tips类型；可选 success | error，默认普通tips。
                        width:320,
                        height:180,
                        content: '<div style="text-align:center;margin-top:90px">不可上传0KB文件</div>'
                    });
                }else{
                    reqAttachmentIdList.push(data.result.files[0].attId);
                }
                //reqAttachmentIdList.push(data.result.files[0].attId);
                fileStatus = true;
            });
            filesUpload.on('remove',function(e,data){
                if(data.attId){
                    delFlag=true;
                    data=data.attId;
                }
                uploadDelete(e,data)
                //e新增自定义remove方法，可根据服务端文件处理结果删除文件列表中的当前行
            });

            filesUpload.on('download',function(e,data){
            	window.location.href= "http://"+window.location.host+AjaxPath.management+'/attachment/downLoadFile/'+data.attId
                /*if(data.attId){
                    delFlag=true;
                    uploadDown(e,data);
                }*/

            });
            filesUpload.on('fail',function(e,data){
               if(data.files[0].size > 31457280){
					var ael=$('#upload tbody.files').find('tr');
					$.each(ael, function(i, obj) {
						if($(obj).hasClass('sn-upload-fail')){
							$(obj).remove();
						}
					})
	        		new Dialog({
	                    mode: 'tips',
	                    delayRmove:2, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
	                    tipsType:'success', //tips类型；可选 success | error，默认普通tips。
	                    width:320,
	                    height:180,
	                    content: '<div style="text-align:center;margin-top:90px">上传文件不能大于30M！</div>'
	                });
             	}else{
             		var ael=$('#upload tbody.files').find('tr');
					$.each(ael, function(i, obj) {
						if($(obj).hasClass('sn-upload-fail')){
							$(obj).remove();
						}
					})
             		new Dialog({
	                    mode: 'tips',
	                    delayRmove:2, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
	                    tipsType:'success', //tips类型；可选 success | error，默认普通tips。
	                    width:320,
	                    height:180,
	                    content: '<div style="text-align:center;margin-top:90px">文件上传失败！</div>'
	                });
             	}
                fileStatus = true;
            })

        };

        function uploadDelete(e,data){
            if(uploadDialog !== null){
                uploadDialog.remove();
            }
            //e新增自定义remove方法，可根据服务端文件处理结果删除文件列表中的当前行
            if(delFlag){
                uploadDialog = new Dialog({
                    title: '提示', //弹窗标题，
                    content: '<div style="text-align:center;margin-top:50px">确定要删除该附件吗？</div>', //弹窗内容，可以是字符串、html代码段,tpl对象。默认为loading状态（由点组成的圈。大段代码建议使用 tpl。
                    okValue: '确定', //确定按钮的文本 默认是 ‘ok’
                    ok: function() {
                        uploadDialog.remove();
                        Util.ajax.getJson(AjaxPath.management+'/attachment/delete/'+data, {}, function(result, isok){
                            uploadDialog.remove();
                            if(result.returnCode==='0000'){
                                reqAttachmentIdList = $.grep(reqAttachmentIdList,function(i,n){
                                    return i!== data;
                                },false);
                                //console.log(reqAttachmentIdList);
                                e.remove();
                                new Dialog({
                                    mode: 'tips',
                                    delayRmove:2, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                                    tipsType:'tips', //tips类型；可选 success | error，默认普通tips。
                                    maxWidth:'226px', //设置tips对话框的最大宽度,默认为226px。仅在tips对话框下生效，该项存在时，width属性将失效。
                                    content: '删除附件成功！'
                                });
                            }else{
                                if(JSON.stringify(data) === "{}"){
                                    new Dialog({
                                        mode: 'tips',
                                        delayRmove:2, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                                        tipsType:'tips', //tips类型；可选 success | error，默认普通tips。
                                        maxWidth:'226px', //设置tips对话框的最大宽度,默认为226px。仅在tips对话框下生效，该项存在时，width属性将失效。
                                        content: '删除附件成功！'
                                    });
                                    $('#upload .files>tr:last-child',$el).remove();
                                }else{
                                    new Dialog({
                                        mode: 'tips',
                                        delayRmove:2, //延迟删除秒数设定 tips默认3秒,非tips默认不关闭。
                                        tipsType:'tips', //tips类型；可选 success | error，默认普通tips。
                                        maxWidth:'226px', //设置tips对话框的最大宽度,默认为226px。仅在tips对话框下生效，该项存在时，width属性将失效。
                                        content: '删除附件失败！'
                                    });
                                }
                            }

                        });
                        $(".ui-popup-backdrop, .ui-popup,.ui-popup-modal,.ui-popup-show,.ui-popup-focus").remove();
                        return false;
                    },
                    cancel: function() {
                        uploadDialog.remove();
                        $(".ui-popup-backdrop, .ui-popup,.ui-popup-modal,.ui-popup-show,.ui-popup-focus").remove();
                        return false;
                    },
                    cancelValue: '取消', //取消按钮的文本 默认是 ‘关闭’
                    width: 300,
                    height: 120,
                    modal:true
                });
                //$('.ui-dialog-close').removeAttr('title')
            }else{
                if(delFlag){
                    e.remove();
                }


            }

        };
        function uploadDown(e,data){
            //e新增自定义remove方法，可根据服务端文件处理结果删除文件列表中的当前行
            if(delFlag){
                window.location.href=data.filePath;
            }else{

            }
        }


        return initialize;
    });